/**
 * 获取baseURL
 */
export const baseURL='http://localhost:8000'

/**
 * 获取uuid
 */
export function getUUID () {
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
      return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
    })
  }

/**
 * 树形数据转换
 * @param {*} data
 * @param {*} id
 * @param {*} pid
 */
export function treeDataTranslate (list) {
  if (!list || !list.length) {
    return []
  }
  let treeListMap = {};
  for (let item of list) {
    treeListMap[item.id] = item
  }
  for (let i = 0; i < list.length; i++) {
    if (list[i].parentId && treeListMap[list[i].parentId]) {
      if (!treeListMap[list[i].parentId].children) {
        treeListMap[list[i].parentId].children = []
      }
      treeListMap[list[i].parentId].children.push(list[i]);
      list.splice(i, 1);
      i--
    }
  }
  return list
}

/**
 * base64图片
 */
export function getBase64(img, callback) {
  const reader = new FileReader();
  reader.addEventListener('load', () => callback(reader.result));
  reader.readAsDataURL(img);
}

/**
 * 是否有权限
 * @param {*} key
 */
import store from '@/store/index'
export function isAuth (key) {
  let arr = []
  store.state.authorization.resources.filter(resource => resource.type === 2).map(resource=>resource.tag.split(',')).map(tag=>{return arr.push(...tag)})
  return arr.indexOf(key) !== -1 || false
}